package com.util;

import org.apache.commons.codec.digest.DigestUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Example {
        public static String md5(String password) {
            String md5Hex = DigestUtils.md5Hex(password);
            return md5Hex;
        }


   /* public static String md5(String password) {
        try {
            // 创建一个MessageDigest实例，指定算法为MD5
            MessageDigest md = MessageDigest.getInstance("MD5");
            // 将密码转换为字节数组并更新MessageDigest
            md.update(password.getBytes());
            // 计算哈希值并返回
            byte[] digest = md.digest();
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                // 将每个字节转换为十六进制字符串并添加到StringBuilder中
                sb.append(String.format("%02x", b & 0xff));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }*/





}
